https://leetcode.cn/problems/two-sum/submissions/625160699/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        int n = nums.size();
        unordered_map<int, int> mp;

        for (int i = 0; i < n; i++) {
            mp[nums[i]] = i;
        }

        vector<int> ans;
        for (int i = 0; i < n; i++) {
            if (mp.count(target - nums[i]) && mp[target - nums[i]] != i) {
                ans.emplace_back(i);
                ans.emplace_back(mp[target - nums[i]]);
                break;
            }
        }
        return ans;
    }
};